home *** CD-ROM | disk | FTP | other *** search
- #!/sprite/cmds/csh -f
- #
- # A script to generate (or regenerate) a kernel module Makefile
- # from a prototype Makefile. If ./Makefile.proto exists, use it, else
- # use a common prototype.
- #
- # This script is invoked from mkmf.
- #
- # Parameters passed in from mkmf as environment variables:
- # DOMACHINES names of machines we are supposed to run mkmf on
- # MKMFDIR directory containing prototype makefiles
- # MKMFFLAGS arguments to all mkmfs run recursively
- # MACHINES list of machine names (e.g. "sun2 sun3"), for
- # which there are machine-specific subdirectories
- # (sun2.md, sun3.md) to hold the object files and
- # any machine-specific source files to use when
- # compiling for that machine
- # MAKEFILE name of makefile to create
- # SUBTYPE information about the type makefile
- #
- # $Header: /sprite/lib/mkmf/RCS/mkmf.kernel,v 1.23 92/06/10 13:04:40 jhh Exp $ (SPRITE) Berkeley
- #
-
- onintr cleanup
-
-
- #
- # Argument processing. (Generalized form, even though just one flag so far.)
- #
- set type=$0
- set type=$type:e
-
- while ($#argv >= 1)
- if ("$1" == '-x') then
- set echo
- endif
- shift
- end
- set subtype=$SUBTYPE
- set name=$cwd:t
- set pref='[a-z_A-Z]'
- #
- # We no longer support the sun3 and the ds3100 so don't run mkmf for those
- # machine types.
- #
- set machines=(`echo $MACHINES | sed -e "s/sun3//g" -e "s/ds3100//g"`)
- set domachines=(`echo $DOMACHINES | sed -e "s/sun3//g" -e "s/ds3100//g"`)
- set makefile=$MAKEFILE
- set distdir=($DISTDIR)
-
- if (-e $makefile.proto) then
- set proto=$makefile.proto
- else
- set proto="${MKMFDIR}/Makefile.$type"
- endif
-
- echo "Generating $makefile for module $name from $proto"
-
-
- set nonomatch
- set hdrs =( ${name}*.h )
- if ("$hdrs" == "${name}*.h") set hdrs=()
- set pubHdrs=(`echo $hdrs | sed -e "s/[^ ]*Int.h//g"`)
- set allSrcs =( ${pref}*.[cylsp] )
- #
- # Check to see if there were any sources. The first check (size == 1)
- # is only necessary because the second check will cause an error if
- # allSrcs contains more than 1024 bytes.
- #
- if ($#allSrcs == 1) then
- if ("$allSrcs" == "${pref}*.[cylsp]") set allSrcs=()
- endif
- set mdsrcs =( *.md/${pref}*.[cylsp] )
- if ($#mdsrcs == 1) then
- if ("$mdsrcs" == "*.md/${pref}*.[cylsp]") set mdsrcs=()
- endif
- set allSrcs=($allSrcs $mdsrcs)
- set mdhdrs =( *.md/${pref}*.h )
- if ($#mdhdrs == 1) then
- if ("$mdhdrs" == "*.md/${pref}*.h") set mdhdrs=()
- endif
- set allHdrs =($hdrs $mdhdrs)
- unset nonomatch
-
- #
- # Use sed to substitute various interesting things into the prototype
- # makefile. The code below is a bit tricky because some of the variables
- # being substituted in can be very long: if the substitution is passed
- # to sed with "-e", the entire variable must fit in a single shell argument,
- # with a limit of 1024 characters. By generating a separate script file
- # for the very long variables, the variables get passed through (to the
- # script file) as many arguments, which gets around the length problem.
- #
-
- rm -f mkmf.tmp.sed
- echo s,"@(ALLSRCS)",$allSrcs,g > mkmf.tmp.sed
- echo s,"@(ALLHDRS)",$allHdrs,g >> mkmf.tmp.sed
- cat $proto | sed -f mkmf.tmp.sed \
- -e "s,@(DATE),`date`,g" \
- -e "s,@(MACHINES),$machines,g" \
- -e "s,@(MAKEFILE),$makefile,g" \
- -e "s,@(NAME),$name,g" \
- -e "s,@(PUBHDRS),$pubHdrs,g" \
- -e "s,@(TEMPLATE),$proto,g" \
- -e "s, $name.ln,,g" \
- -e "s,@(DISTDIR),$distdir,g" \
- -e "s,@(TYPE),$subtype,g" \
- > $makefile
- rm -f mkmf.tmp.sed
-
- setenv PARENTDIR $cwd
-
- if ($#domachines != 1) then
- cat << EOF > "#mkmf.$$"
- all :: $domachines
- $domachines ::
- @ cd \$@.md
- @ mkmf \$MKMFFLAGS -f md.mk
- @ mv md.mk md.mk.tmp
- @ sed -e "s| \$@\.md/$name\.o||g" md.mk.tmp > md.mk
- @ rm -f md.mk.tmp
- EOF
- pmake -f "#mkmf.$$"
- else
- foreach i ($domachines)
- (cd $i.md; mkmf $MKMFFLAGS -f md.mk; mv md.mk md.mk.tmp; sed -e "s| $i\.md/$name\.o||g" md.mk.tmp > md.mk; rm -f md.mk.tmp)
- end
- endif
-
- cleanup:
- rm -f "#mkmf.$$" mkmf.tmp.sed
-